//
//  MovieCell.m
//  TableView
//
//  Created by Carl_fang on 15/3/28.
//  Copyright (c) 2015年 Carl_fang. All rights reserved.
//

#import "MovieCell.h"
#import "UIImageView+WebCache.h"

@interface MovieCell()

@property (nonatomic, retain) UIImageView *movieImage;
@property (nonatomic, retain) UILabel *titleCnLabel;
@property (nonatomic, retain) UILabel *titleEnLabel;
@property (nonatomic, retain) UILabel *timeLabel;
@property (nonatomic, retain) UILabel *typeLabel;
@property (nonatomic, retain) UILabel *playTimeLabel;
@property (nonatomic, retain) UILabel *introduceLabel;
@property (nonatomic, retain) UILabel *ratingLabel;

@end

@implementation MovieCell

- (void)setDetailModel:(DetailModel *)detailModel
{
    NSURL *url = [NSURL URLWithString:detailModel.img];
    [self.movieImage setImageWithURL:url];
    self.titleCnLabel.text = detailModel.t;
    self.titleEnLabel.text = detailModel.tEn;
    self.timeLabel.text = detailModel.d;
    
    
    //NSString *typeStr = [detailModel.rd substringToIndex:4];
    //NSLog(@"%@",typeStr);
//
//    NSString *month = [detailModel.rd substringWithRange:NSMakeRange(4, 2)];
//    NSLog(@"%@",month);
    
    
    
    //NSString *dateStr = @"20100223";
    // Convert string to date object
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyyMMdd"];
    NSDate *date = [dateFormat dateFromString:detailModel.rd];
    // Convert date object to desired output format
    [dateFormat setDateFormat:@"YYYY年M月d日"];
    //NSLog(@"-----%@",[dateFormat stringFromDate:date]);
    NSString *dateStr = [NSString stringWithFormat:@"%@上映",[dateFormat stringFromDate:date]];
    self.playTimeLabel.text = dateStr;
    //NSDate *date = [NSDate date];
    //NSLog(@"%@",date);
    
//    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
//    [dateFormat setDateFormat:@"YYYY年M月d日"];
// 
//    NSString *dateString = [dateFormat stringFromDate:detailModel.rd];
//    NSLog(@"..SSS..%@",dateString);
    
    
    
    
    //self.typeLabel.text = detailModel.p;
    //NSString *timeStr = [NSString stringWithFormat:@"%@年上映",typeStr];
    
    //self.playTimeLabel.text = timeStr;

    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _movieImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 180)];
        //_movieImage.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_movieImage];
        _titleCnLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 10, 180, 20)];
        //_titleCnLabel.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:_titleCnLabel];
        _titleEnLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 35, 150, 10)];
        //_titleEnLabel.backgroundColor = [UIColor yellowColor];
        _titleEnLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_titleEnLabel];
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 50, 70, 10)];
        //_timeLabel.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_timeLabel];
        _typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 60, 30, 10)];
        //_typeLabel.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_typeLabel];
        _playTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 70, 200, 10)];
        //_playTimeLabel.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_playTimeLabel];
        
        
    }
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
